package com.auntvt.timo.jpax.springbootstarter.config.properties;

import com.auntvt.timo.jpax.springbootstarter.primarykey.JpaxStrategy;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * jpax主键配置类
 *
 * @author 小懒虫 <auntvt＠163.com>
 * @date 2021/5/28
 */
@Data
@Component
@ConfigurationProperties(prefix = "timo.jpax.primary-key")
public class JpaxPrimaryKeyProperties {

    /**
     * 默认主键生成策略
     * {支持jpa自带主键生成算法：uuid2、guid、uuid、uuid.hex、assigned等主键生成算法}
     * {注意：在自动生成表时不会配置主键ID为自动增长}
     */
    private String defaultStrategy = JpaxStrategy.SNOW_FLAKE;

    /**
     * 雪花算法参数配置
     */
    private SnowFlake snowFlake = new SnowFlake();

    /**
     * 参数列表-用于自定义的主键生成器参数设置
     */
    private Map<String, String> parameters = new HashMap<>();

    /**
     * 雪花算法配置类
     */
    @Data
    public static class SnowFlake {

        /**
         * 终端ID
         */
        private long workerId = 1;

        /**
         * 数据中心ID
         */
        private long datacenterId = 1;
    }

}
